using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerStats : CharacterStats
{
    private Player player;
    protected override void Start()
    {
        base.Start();
        player = GetComponent<Player>();
    }

    protected override void Update()
    {
        base.Update();
    }

    public override void TakeDamage(int _damage)
    {
        base.TakeDamage(_damage);
    }

    protected override void Die()
    {
        base.Die();
        player.Die();//角色死亡状态
        GameManager.instance.lostCurrencyAmount = PlayerManager.instance.currency;
        PlayerManager.instance.currency = 0;
        GetComponent<PlayerItemDrop>()?.GenerateDrop();// 死亡掉落

    }

    // 保护的重写方法，用于减少健康值
    protected override void DecreaseHealthBy(int _damage)
    {
        // 调用基类的减少健康值方法
        base.DecreaseHealthBy(_damage);

        if (_damage > GetMaxHealthValue() * .3f)
        {
            player.SetupKnockbackPower(new Vector2(10, 15));
            player.fx.ScreenShake(player.fx.shakeHighDamage);
            AudioManager.instance.PlaySFX(33, null);
        }
        // 获取当前装备的护甲
        ItemData_Equipment currenArmor = Inventory.instance.GetEquipment(EquipmentType.Armor);

        // 如果当前护甲不为空，则执行护甲的效果
        if (currenArmor != null)
        {
            currenArmor.ExecuteItemEffect(player.transform);
        }
    }

    public override void OnEvasion()
    {
        Debug.Log("闪避");
        player.skill.dodge.CreateMirageOnDodge();
    }

    public void CloneDoDamage(CharacterStats _targetStats, float _attackMultiplier)
    {
        // 判断是否闪避
        if (TargetCanAvoidAttack(_targetStats))
        {
            return;
        }

        //计算攻击加力量造成的伤害
        int totalDamage = damage.GetValue() + strength.GetValue();

        if (_attackMultiplier > 0)
        {
            totalDamage = Mathf.RoundToInt(totalDamage * _attackMultiplier);
        }
        //暴击后计算暴击伤害
        if (CanCrit())
        {
            totalDamage = CalculateCriticalDamge(totalDamage);
        }
        //减去护甲
        totalDamage = CheckTargetArmor(_targetStats, totalDamage);
        // 造成伤害
        _targetStats.TakeDamage(totalDamage);
    }
}
